#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
using namespace std;
  struct ListNode {
      int val;
      ListNode *next;
      ListNode() : val(0), next(nullptr) {}
      ListNode(int x) : val(x), next(nullptr) {}
      ListNode(int x, ListNode *next) : val(x), next(next) {}
  };
 
class Solution {
public:
    void reorderList(ListNode* head) {
        ListNode* slow = head;
        ListNode* fast = head;
        while (fast && fast->next)
        {
            slow = slow->next;
            fast = fast->next->next;
        }
        //
        ListNode* cur = slow->next;
        ListNode* head2 = new ListNode(0);
        slow->next = nullptr;
        while (cur)
        {
            ListNode* next = cur->next;
            cur->next = head2->next;
            head2->next = cur;
            cur = next;
        }
        ListNode* ret = new ListNode(0);
        ListNode* cur1 = head;
        ListNode* cur2 = head2->next;
        ListNode* prev = ret;
        while (cur1)
        {

            prev->next = cur1;
            prev = prev->next;
            cur1 = cur1->next;
            if (cur2)
            {
                prev->next = cur2;
                prev = prev->next;
                cur2 = cur2->next;
            }
        }
        delete ret;
        delete head2;

    }
};